package com.mycat.task.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mycat.task.dao.mapper.ScheduleTaskMapper;
import com.mycat.task.entity.ScheduleTask;
import com.mycat.task.service.ScheduleTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ScheduleTaskServiceImpl implements ScheduleTaskService {

    @Autowired
    private ScheduleTaskMapper scheduleTaskMapper;

    @Override
    public void save(ScheduleTask scheduleTask) {
        scheduleTask.setCreateDate(new Date());
        scheduleTaskMapper.insertUseGeneratedKeys(scheduleTask);
    }

    @Override
    public void edit(ScheduleTask scheduleTask) {
        scheduleTask.setUpdateDate(new Date());
        scheduleTaskMapper.updateByPrimaryKeySelective(scheduleTask);
    }

    @Override
    public void delete(Integer[] ids) {
        for (Integer id : ids) {
            scheduleTaskMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public ScheduleTask findScheduleTask(Integer id) {
        return  scheduleTaskMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<ScheduleTask> page(Page<ScheduleTask> page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<ScheduleTask>  datas =  scheduleTaskMapper.selectAll();
        PageInfo<ScheduleTask> pageInfo = new PageInfo<>(datas);
        return pageInfo;
    }

}